package com.ibeeking.gmc.global.g.rest.controller.v1;

import com.ibeeking.gmc.global.g.rest.service.IRedisService;
import com.ibeeking.nematos.constants.enums.OperateLogTypeEnum;
import com.ibeeking.nematos.log.annotation.Log;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @ClassName RedisController控制器
 * @Description
 * @Author ibeeking
 * @Date 2020-12-02 16:06
 **/
@RestController
@RequestMapping("/g/redis/v1")
public class RedisController {

    @Resource
    private IRedisService redisServiceImpl;

    @Log(logType = OperateLogTypeEnum.QUERY, describe = "查看")
    @GetMapping(value = "/view/{database}/{key}")
    public String view(@PathVariable("database") Integer database, @PathVariable("key") String key) {
        return redisServiceImpl.view(database, key);
    }

    @Log(logType = OperateLogTypeEnum.QUERY, describe = "根据前缀查看")
    @GetMapping(value = "/viewByPrefix/{database}/{keyPrefix}")
    public List<String> viewByPrefix(@PathVariable("database") Integer database, @PathVariable("keyPrefix") String keyPrefix) {
        return redisServiceImpl.viewByPrefix(database, keyPrefix);
    }

    @Log(logType = OperateLogTypeEnum.DEL, describe = "删除单个redis key")
    @GetMapping(value = "/delOne/{database}/{key}")
    public Boolean delOne(@PathVariable("database") Integer database, @PathVariable("key") String key) {
        return redisServiceImpl.delOne(database, key);
    }

    @Log(logType = OperateLogTypeEnum.DEL, describe = "根据key前缀删除")
    @GetMapping(value = "/delByPrefix/{database}/{keyPrefix}")
    public Boolean delByPrefix(@PathVariable("database") Integer database, @PathVariable("keyPrefix") String keyPrefix) {
        return redisServiceImpl.delByPrefix(database, keyPrefix);
    }

}